package com.ruoyi.teacher.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.teacher.domain.TeacherCourse;
import com.ruoyi.teacher.service.ITeacherCourseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 教师与课程的多对多关系Controller
 * 
 * @author ruoyi
 * @date 2024-12-16
 */
@RestController
@RequestMapping("/teacher/course")
public class TeacherCourseController extends BaseController
{
    @Autowired
    private ITeacherCourseService teacherCourseService;

    /**
     * 查询教师与课程的多对多关系列表
     */
    @PreAuthorize("@ss.hasPermi('teacher:course:list')")
    @GetMapping("/list")
    public TableDataInfo list(TeacherCourse teacherCourse)
    {
        startPage();
        List<TeacherCourse> list = teacherCourseService.selectTeacherCourseList(teacherCourse);
        return getDataTable(list);
    }

    /**
     * 导出教师与课程的多对多关系列表
     */
    @PreAuthorize("@ss.hasPermi('teacher:course:export')")
    @Log(title = "教师与课程的多对多关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeacherCourse teacherCourse)
    {
        List<TeacherCourse> list = teacherCourseService.selectTeacherCourseList(teacherCourse);
        ExcelUtil<TeacherCourse> util = new ExcelUtil<TeacherCourse>(TeacherCourse.class);
        util.exportExcel(response, list, "教师与课程的多对多关系数据");
    }

    /**
     * 获取教师与课程的多对多关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('teacher:course:query')")
    @GetMapping(value = "/{teacherId}")
    public AjaxResult getInfo(@PathVariable("teacherId") String teacherId)
    {
        return success(teacherCourseService.selectTeacherCourseByTeacherId(teacherId));
    }

    /**
     * 新增教师与课程的多对多关系
     */
    @PreAuthorize("@ss.hasPermi('teacher:course:add')")
    @Log(title = "教师与课程的多对多关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeacherCourse teacherCourse)
    {
        return toAjax(teacherCourseService.insertTeacherCourse(teacherCourse));
    }

    /**
     * 修改教师与课程的多对多关系
     */
    @PreAuthorize("@ss.hasPermi('teacher:course:edit')")
    @Log(title = "教师与课程的多对多关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeacherCourse teacherCourse)
    {
        return toAjax(teacherCourseService.updateTeacherCourse(teacherCourse));
    }

    /**
     * 删除教师与课程的多对多关系
     */
    @PreAuthorize("@ss.hasPermi('teacher:course:remove')")
    @Log(title = "教师与课程的多对多关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{teacherIds}")
    public AjaxResult remove(@PathVariable String[] teacherIds)
    {
        return toAjax(teacherCourseService.deleteTeacherCourseByTeacherIds(teacherIds));
    }
}
